<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <el-form label-width="120px" style="width:500px">
              <el-form-item label="姓名" prop="username">
                <el-input v-model="formData.username" />
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="formData.password" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="updateFn">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <UserInfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserInfoById } from '@/api/user'
import UserInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
import { saveUserDetailById } from '@/api/employees'
export default {
  components: {
    UserInfo, JobInfo
  },
  data() {
    return {
      formData: {
        username: '',
        password: ''
      },
      rules: { username: [
        { required: true, message: 'bitian', trigger: 'blur' },
        { min: 2, max: 5, message: '密码长度为6到12', trigger: 'blur' }
      ],
      password: [
        { required: true, message: 'bitian', trigger: 'blur' },
        { min: 6, max: 15, message: '密码长度为6到12', trigger: 'blur' }
      ] }
    }
  },
  async created() {
    const res = await getUserInfoById(this.$route.params.id)
    console.log(res)
    this.formData = res
    this.formData.password = ''
  },
  methods: {
    async updateFn() {
      await saveUserDetailById(this.formData)
    }
  }

}
</script>

  <style>

  </style>
